package com.lijing.controller;

import com.lijing.model.Club;
import com.lijing.model.LeaveMsg;
import com.lijing.model.User;
import com.lijing.service.LeaveMsgService;
import com.lijing.util.JSONResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class LeaveMsgController {

    @Autowired
    private LeaveMsgService leaveMsgService;

    @RequestMapping("/getLeaveMsgListByClub")
    public List<LeaveMsg> getLeaveMsgListByClub(Integer cid){
        return leaveMsgService.getLeaveMsgListByClub(cid);
    }

    @RequestMapping("/addLeaveMsg")
    public String addLeaveMsg(LeaveMsg leaveMsg, HttpSession session){
        User user = (User) session.getAttribute("user");
        Club club = user.getClub();
        leaveMsg.setWritter(user);
        leaveMsg.setClub(club);
        leaveMsgService.addLeaveMsg(leaveMsg);
        return JSONResponse.getOK("添加成功！");
    }

    @RequestMapping("/deleteLeaveMsg")
    public String deleteLeaveMsg(Integer lid){
        leaveMsgService.deleteLeaveMsg(lid);
        return JSONResponse.getOK("删除成功");
    }

}
